#include <stdio.h>
#include <string.h>

char getstr(char *buf, int start, int length)
{
    if (strlen(buf) < length || length > strlen(buf) - start || start < 0 || length < 0)
    {
        printf("ERROR!!!!");
        return 0;
    }
    
    int end = start + length;
    char ar[30] = {0};
    for (int i = start, j = 0; i < end && j < 29; i++, j++) 
    {  
        ar[j] = buf[i];  
    }  
    printf("%s", ar);
}

int main()
{
    int start, length;
    char buf[30] = {0};
    printf("请输入一个字符串:");
    scanf("%s",buf);
    printf("请输入开始位置和长度:");
    scanf("%d%d", &start, &length);
    getstr(buf, start, length);
}